package com.loong.tool.lang;

/**
 * 字符串工具类
 * 
 * @author 张成轩
 */
public class Strings {

	/**
	 * 字符串是否不为空
	 * 
	 * @param s 字符串
	 * @return 是否不为空
	 */
	public static boolean isNotNull(String s) {

		return !isNull(s);
	}

	/**
	 * 字符串是否为空
	 * 
	 * @param s 字符串
	 * @return 是否为空
	 */
	public static boolean isNull(String s) {

		if (s == null || s.trim().equals(""))
			return true;
		return false;
	}

	/**
	 * 拼装字符串
	 * 
	 * @param split 分隔
	 * @param strings 字符串集
	 * @return 字符串
	 */
	public static String join(String split, Iterable<?> strings) {

		StringBuilder sb = new StringBuilder();
		for (Object s : strings) {
			if (s == null)
				continue;
			if (sb.length() != 0)
				sb.append(split);
			sb.append(s);
		}
		return sb.length() == 0 ? null : sb.toString();
	}

	/**
	 * 拼装字符串
	 * 
	 * @param split 分隔
	 * @param strings 字符串集
	 * @return 字符串
	 */
	public static String join(String split, Object... strings) {

		StringBuilder sb = new StringBuilder();
		for (Object s : strings) {
			if (s == null)
				continue;
			if (sb.length() != 0)
				sb.append(split);
			sb.append(s);
		}
		return sb.length() == 0 ? null : sb.toString();
	}

	/**
	 * 连接字符串
	 * 
	 * @param strings 字符串集
	 * @return 字符串
	 */
	public static String concat(Iterable<?> strings) {

		StringBuilder sb = new StringBuilder();
		for (Object s : strings)
			if (s != null)
				sb.append(s);
		return sb.length() == 0 ? null : sb.toString();
	}

	/**
	 * 连接字符串
	 * 
	 * @param strings 字符串集
	 * @return 字符串
	 */
	public static String concat(Object... strings) {

		StringBuilder sb = new StringBuilder();
		for (Object s : strings)
			if (s != null)
				sb.append(s);
		return sb.length() == 0 ? null : sb.toString();
	}
}
